package com.nail.api.user.dao;


import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.nail.api.user.bean.User;
import com.nail.dao.IBaseDao;

@Mapper
public interface IUserDao extends IBaseDao<User>{
    @Select("select * from user where user_name = #{userName}")
    public User getUserByName(@Param("userName")String userName);
    
    @Select("select * from user where mobile = #{mobile}")
    public User getUserByMobile(@Param("mobile")String mobile);

    @Select("select * from user where user_name = #{userName} and password = #{passWord}")
    public User getUserByNameAndPassword(@Param("userName") String userName, @Param("passWord")String passWord);

    @Insert("INSERT INTO user(user_name,password,mobile,email,create_time,status,memo,type,country) VALUES(#{userName},#{password},#{mobile},#{email},#{createTime},#{status},#{memo},#{type},#{country})")
    public int insertUser(User user);
    
    @Update("update user set last_login_time = now() where id = ${id}")
    public void setLastLoginTime(@Param("id")Long id);

    @Select("SELECT SUM(total_price) AS totalMonney,SUM(IF(update_time > ${today},total_price,0) ) AS todayMonney FROM `indent` WHERE state != -1 AND pay_status = 1")
    public Map<String, Object> getMoneyStatistics(@Param("today")String today);
    
    @Select("SELECT COUNT(id) AS total,SUM(IF(create_time > ${today},1,0)) AS creator,SUM(IF(last_login_time > ${today},1,0)) AS login FROM `user` ")
    public Map<String, Object> getUserStatistics(@Param("today")String today);
}
